package openofficetest;

import java.io.File;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;

public class OpenOfficeTransferTest {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	private String connectIp = "192.168.56.101";
	private int connectPort = 8100;

	// word转pdf,使用openoffice进行转换
	@Test
	public void wordToPdfTest() {

		OpenOfficeConnection connection = null;
		logger.info("connecting start...");
		try {
			
			connection = new SocketOpenOfficeConnection(connectIp, connectPort);
			connection.connect();

			logger.info("connected...> " +connection);
			DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);

			logger.info("convert starting.....");
			long startMs = System.currentTimeMillis();
			converter.convert(new File("D:\\temp\\1.docx"), new File("D:\\temp\\1.pdf"));
			long endMs = System.currentTimeMillis();
			logger.info("convert success, spend time is : {} ms.",(endMs-startMs) );

		} catch (Exception e) {
			logger.error("", e);
		} finally {

			if(connection != null) {
				connection.disconnect();
				logger.info("connection disconnected. ");
			}
		}
	}

}
